package com.freesky.biz.activity.controller;

import com.freesky.biz.activity.domain.TActivityConfig;
import com.freesky.biz.activity.domain.TAlipayActivityConfigExport;
import com.freesky.biz.activity.domain.TStockMonitor;
import com.freesky.biz.activity.service.IStockMonitorService;
import com.freesky.biz.utils.SeqUtil;
import com.freesky.common.annotation.Log;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import com.freesky.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/activity/stock/monitor")
public class StockMonitorController extends BaseController {

    @Autowired
    private IStockMonitorService stockMonitorService;

    /**
     * 获取券监控列表
     */
    @PreAuthorize("@ss.hasPermi('activity:stockmonitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStockMonitor stockMonitor) {
        startPage();
        List<TStockMonitor> list = stockMonitorService.findList(stockMonitor);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('activity:stockmonitor:list')")
    @GetMapping("/summary")
    public AjaxResult summary(TStockMonitor stockMonitor) {
        return AjaxResult.success(stockMonitorService.selectSummaryData(stockMonitor));
    }

    @PreAuthorize("@ss.hasPermi('activity:stockmonitor:edit')")
    @Log(title = "活动状态", businessType = BusinessType.UPDATE)
    @PostMapping("/alarmSet")
    public AjaxResult alarmSet(@Validated @RequestBody TStockMonitor stockMonitor) {
        return toAjax(stockMonitorService.updateAlarmFlag(stockMonitor));
    }

    @Log(title = "活动状态", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('activity:stockmonitor:export')")
    @GetMapping("/export")
    public AjaxResult export(TStockMonitor stockMonitor,
                             HttpServletResponse response) {
        return stockMonitorService.exportFile(stockMonitor);
    }
}
